<template>
	<view>
		<uni-title title="测试页面" type="h4" align="center" color="#0aaa87"></uni-title>
		<uni-popup type="message" ref="popup">
			<uni-popup-message :type="msgType" :message="msg" :duration="2000"></uni-popup-message>
		</uni-popup>

		<u-notify ref="uNotify" message=""></u-notify>

		<u-divider text="测试连接"></u-divider>


		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="test" type="info" text="测试异步请求"></u-button>
		</view>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="testAsync" type="success" text="测试同步连接"></u-button>
		</view>

		<u-divider text="页面跳转"></u-divider>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button plain @click="toLogin" type="success">去登录</u-button>
		</view>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button plain @click="toRegister" type="info">去注册</u-button>
		</view>

		<u-divider text="测试get/post请求"></u-divider>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="testGetRequest" type="info" text="get请求"></u-button>
		</view>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="testPostRequest" type="info" text="post请求"></u-button>
		</view>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="testSession" type="info" text="session"></u-button>
		</view>
		<view style="margin: 10px;width: 100px;display: inline-block;">
			<u-button @click="getKaptchaCode" type="info" text="得到验证码"></u-button>
		</view>

	</view>
</template>

<script>
	import $api from '../../api/api'
	import {
		getSession,
		testLink
	} from '../../api/test/test'

	export default {
		data() {
			return {
				msg: "",
				msgType: "success",
				username: "aaaaaa"
			}
		},
		methods: {
			testGetRequest() {
				let data = {
					username: this.usernamme,
					userId: 0,
				}
				$api.user.checkUsernameCanUse(data).then(res => {
					console.log(res);
				})
			},
			testSession() {
				$api.test.getSession().then(res => {
					console.log(res);
				})
			},
			getKaptchaCode() {
				$api.test.getKaptchaCode().then(res => {
					console.log(res);
				})
			},
			async testPostRequest() {
				let data = {
					id: 10
				}
				let {
					data: res
				} = await $api.aphorism.getOneAphorism(data)
				console.log(res.dataMap.aphorism.content);
				this.$refs.uNotify.success(res.dataMap.aphorism.content)
			},
			toLogin() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			toRegister() {
				uni.navigateTo({
					url: "/pages/register/register"
				})
			},
			test() {
				$api.test.testLink().then(res => {
					console.log(res);
					if (res.data.code == 200) {
						this.msg = res.data.msg
						this.msgType = "success"
					} else {
						this.msgType = "error"
						this.msg = "连接失败!"
					}
				})
				this.$refs.uNotify.show({
					type: this.msgType,
					message: this.msg,
					duration: 1000 * 3,
				})
			},
			async testAsync() {
				let {
					data: res
				} = await $api.test.testLink();
				console.log(res);
				if (res.code == 200) {
					this.msg = res.msg
					this.msgType = "success"
				} else {
					this.msgType = "error"
					this.msg = "连接失败!"
				}
				this.$refs.uNotify.show({
					type: this.msgType,
					message: this.msg,
					duration: 1000 * 3,
				})
			}
		}
	}
</script>

<style scoped>

</style>